import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: "/",
            name: "home",
            component: Home,
            meta: {
                title: "首页 - 西旺数字",
                description: "我们是一家致力于创新的科技公司，提供最优质的服务和解决方案",
            },
        },
        {
            path: "/about",
            name: "about",
            component: () => import("../views/About.vue"),
            meta: {
                title: "关于我们 - 西旺数字",
                description: "了解我们的故事、团队和企业文化",
            },
        },
        {
            path: "/products",
            name: "products",
            component: () => import("../views/Products.vue"),
            meta: {
                title: "产品中心 - 西旺数字",
                description: "查看我们的产品列表，为您提供最佳解决方案",
            },
        },
        {
            path: "/contact",
            name: "contact",
            component: () => import("../views/Contact.vue"),
            meta: {
                title: "联系我们 - 西旺数字",
                description: "查看我们的产品列表，为您提供最佳解决方案",
            },
        },
    ],
});

// SEO优化：动态更新页面标题和描述
router.beforeEach((to, _, next) => {
    document.title = to.meta.title as string;
    const metaDescription = document.querySelector('meta[name="description"]');
    if (metaDescription) {
        metaDescription.setAttribute("content", to.meta.description as string);
    }
    next();
});

export default router;
